package cn.com.lsy.product.lepao.service.impl;

import cn.com.lsy.product.lepao.common.Constant;
import cn.com.lsy.product.lepao.model.dao.LpIconTypeTblMapper;
import cn.com.lsy.product.lepao.model.entities.LpIconTypeTbl;
import cn.com.lsy.product.lepao.model.entities.LpIconTypeTblExample;
import cn.com.lsy.product.lepao.service.IIconTypeService;
import cn.com.lsy.product.lepao.util.CommonFunctionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.util.List;

@Service
public class IconTypeService implements IIconTypeService {

    @Autowired
    LpIconTypeTblMapper lpIconTypeTblMapper;

    @Override
    public List<LpIconTypeTbl> selectList() {

        LpIconTypeTblExample example = new LpIconTypeTblExample();
        example.createCriteria().andIsDeleteNotEqualTo(Constant.status.deleted);

        return lpIconTypeTblMapper.selectByExample(example);
    }

    @Override
    public LpIconTypeTbl selectInfo(int id) {

        return lpIconTypeTblMapper.selectByPrimaryKey(id);
    }

    @Override
    public boolean update(LpIconTypeTbl param) {

        if (lpIconTypeTblMapper.updateByPrimaryKeySelective(param) > 0) {

            return true;

        } else {

            return false;
        }
    }

    @Override
    public boolean delete(int id) {

        if (lpIconTypeTblMapper.deleteByPrimaryKey(id) > 0) {

            return true;

        } else {

            return false;
        }
    }

    @Override
    public boolean insert(LpIconTypeTbl param) {

        try {
            param.setInsertTime(CommonFunctionUtil.getDateTime(Constant.formatType.second));

            if (lpIconTypeTblMapper.insertSelective(param) > 0) {

                return true;

            } else {

                return false;
            }

        } catch (ParseException e) {
            e.printStackTrace();
        }

        return false;
    }
}
